<!DOCTYPE html>
<html>
	<head>
		<#include "/templates/commons/head.html">
		<script type="text/javascript">
			/**
			*点击查询按钮，查询列表
			*/
			function query(){
				document.opForm.action = "${ctx!}/OrgController/queryList.do";
				document.opForm.submit();
			}
			/**
			*点击添加按钮进入添加页面
			*/
			function add(){
				document.opForm.action = "${ctx!}/OrgController/add.do";
				document.opForm.submit();
			}
			/**
			*点击修改按钮进入修改页面
			*/
			function edit(id){
				document.opForm.action = "${ctx!}/OrgController/edit.do?orgId=" + id;
				document.opForm.submit();
			}
			/**
			*点击删除按钮删除信息
			*/
			function del(){
				var isDel = false;
				if(seleBox("ids")){
				    var ids = document.getElementsByName("ids");
				    var arr = Common.checkboxVals(ids);
				    if ($.inArray("86", arr) > -1) {
						$("#div-message").html("不能删除系统机构！");
						return;
				    }
					layer.confirm("您是否确定要删除？", {
					    btn: ['确定', '取消']
						}, function() {
						    document.opForm.action = "${ctx!}/OrgController/delete.do";
							document.opForm.submit();
						}, function() {
					});
				}
			}
			
			/*
			* 机构授权
			*/
			function orgAuth(){
			    if(seleBox("ids")){
				    var ids = document.getElementsByName("ids");
				    if (Common.checkboxLength(ids) > 1) {
						layer.alert("只能选择一条记录!");
						return;
				    }
					layer.open({
						type: 2,
						title: '授权机构',
						shade: 0.4, //弹窗后边是否显示阴影 可以填true/false 或者0.？透明度
						shadeClose: true,//点击阴影是否关闭弹窗
						maxmin: true, //开启最大化最小化按钮
						closeBtn: 0, //不显示关闭按钮
						btn: ['确定','取消'],
						area: [document.body.clientWidth * 0.4 + "px", document.body.clientWidth * 0.4 / 1.2 + "px"],
						content: '${ctx!}/OrgController/getMenuList.do?ids=' + Common.checkboxVals(ids)[0],
						yes: function(index){
						    var iframeWin = window["layui-layer-iframe" + index];
						    iframeWin.dialogSave(function(message) {
								Common.dialogEditCallback(index, message);
						    });
				    	},
				    	btn2: function(index) {
				    		layer.close(index);
				    	}
					});
				}
			}
			
			function orgAdmin(){
			    if(seleBox("ids")){
					var ids = document.getElementsByName("ids");
				    if(Common.checkboxLength(ids) > 1){
				    	layer.alert("只能选择一条记录!");
				    	return;
				    }
				    var res = "";
				  	//先授权再新建机构管理员
				    Common.network("${ctx!}/OrgController/checkAuthOk.do", "POST", {"orgId": Common.checkboxVals(ids)[0]}, false, function(data) {
						res = data;
				    });
				    if (res == "0") {
						layer.alert("请先进行授权操作");
						return;
				    }
				    layer.open({
						type: 2,
						title: '添加机构管理员',
						shade: 0.4, //弹窗后边是否显示阴影 可以填true/false 或者0.？透明度
						shadeClose: true,//点击阴影是否关闭弹窗
						maxmin: true, //开启最大化最小化按钮
						closeBtn: 0, //不显示关闭按钮
						btn: ['确定','取消'],
						area: [document.body.clientWidth * 0.4 + "px", document.body.clientWidth * 0.3 / 1.2 + "px"],
						content: '${ctx!}/OrgController/adminAdd.do?id=' + Common.checkboxVals(ids)[0],
						yes: function(index){
						    var iframeWin = window["layui-layer-iframe" + index];
						    iframeWin.dialogSave(function(message) {
								Common.dialogEditCallback(index, message);
						    });
				    	},
				    	btn2: function(index) {
				    		layer.close(index);
				    	}
					});
				}
			}
		</script>
	</head>
	<body>
		<div id="div-body" class="body">
			<form id="opForm" name="opForm" method="post" class="layui-form">
				<div class="search-head">
					<!-- 顶部搜索&按钮栏 Start -->
			        <blockquote class="layui-elem-quote">
						<!-- 头部右边搜索条件 Start -->
			            <div class="layui-form layui-list-btn-group">
		                	<!-- 关键字搜索 Start -->
		                	<div class="input-block">
			                	<label class="layui-form-label">关键字</label>
			                    <div class="layui-input-inline">
			                        <input type="text" name="param_keyWord" placeholder="机构名称，负责人" autocomplete="off" class="layui-input" />
			                    </div>
		                	</div>
		                	<!-- 关键字搜索 End -->
			            </div>
			            <!-- 头部右边搜索条件 End -->
					</blockquote>
		        	<!-- 按钮 Start -->
			        <blockquote class="layui-elem-quote list-btn-group">
						<div class="layui-btn-group">
							<#if Session.CUR_MENU.addRole == 1>
								<button class="layui-btn" type="button" onclick="add();"><i class="layui-icon">&#xe654;</i>新增</button>
							</#if>
							<#if Session.CUR_MENU.deleteRole == 1>
								<button class="layui-btn" type="button" onclick="del();"><i class="layui-icon">&#xe640;</i>删除</button>
							</#if>
							<#if Session.CUR_MENU.updateRole == 1>
								<input type="button" class="layui-btn" onclick="orgAuth();" value="授权">
					            <input type="button" class="layui-btn" onclick="orgAdmin();" value="添加管理员">
							</#if>
						</div>
						<#if Session.CUR_MENU.selectRole == 1>
							<button class="layui-btn query-btn layui-btn-danger" type="button" onclick="query();"><i class="layui-icon">&#xe615;</i>查询</button>
						</#if>
			        </blockquote>
					<!-- 按钮 End -->
			        <!-- 顶部搜索&按钮栏End -->
				</div>
		        <!-- 顶部搜索&按钮栏 End -->
		        <!-- table list group Start -->
				<div class="container">
					<!-- message Start -->
		        	<div id="div-message">${message!}</div>
		        	<!-- message End -->
		        	<!-- table list Start -->
					<div class="data-grid-group">
						<table lay-filter="data-grid" class="layui-table dymanic-table">
							<thead>
								<tr>
									<th lay-data="{field:'ids', checkbox: true, align: 'center', width: '5%'}"></th>
									<th lay-data="{field:'index', align: 'center', sort:true, width: '7%'}">序号</th>
									<th lay-data="{field:'orgId', align: 'center', sort:true, width: '16%'}">机构编号</th>
									<th lay-data="{field:'orgName', align: 'left', sort:true, width: '22%'}">机构名称</th>
									<th lay-data="{field:'cityCode', align: 'center', sort:true, width: '15%'}">省市</th>
									<th lay-data="{field:'phone', align: 'center', sort:true, width: '15%'}">联系电话</th>
									<th lay-data="{field:'level', align: 'center', sort:true, width: '10%'}">级别</th>
									<th lay-data="{field:'zipCode', align: 'center', sort:true, width: '10%'}">邮编</th>
								</tr>
							</thead>
							<tbody>
								<#if resultList?exists>
									<#list resultList as OrgBean>
										<tr>
											<td>
												<input id="ids" name="ids" lay-skin="primary" type="checkbox" org-type="${OrgBean.orgType}" value="${OrgBean.orgId!''}"/>
											</td>
											<td>${OrgBean_index + 1}</td>
											<td>
												${OrgBean.orgId!'-'}
											</td>
											<td>
												<a href="javascript:void(0);" onclick="edit('${OrgBean.orgId!''}')">
													${OrgBean.orgName!'-'}
												</a>
											</td>
											<td><@city cityCode="${OrgBean.cityCode!''}">${cityName}</@city></td>
											<td>${OrgBean.phone!'-'}</td>
											<td>${OrgBean.level!'-'}</td>
											<td>${OrgBean.zipCode!'-'}</td>
										</tr>
									</#list>
								</#if>
							</tbody>
						</table>
					</div>
					<!-- table list End -->
				</div>
				<!-- table list group End -->
			</form>
		</div>
	</body>
</html>